package map;

import java.util.Map;
import java.util.TreeMap;
import java.util.function.BiConsumer;

public class MapTest1 {
    public static void main(String[] args) {
        String s1="ababc";
        TreeMap<Character,Integer> tm=new TreeMap<>();
        final var charArray = s1.toCharArray();
        for (char c : charArray) {
//            假如tm不含C的话
            if(!tm.containsKey(c)){
                tm.put(c,1);
            }else{
//                存在的话，说明不是第一次出现，获取旧值的value值+1
                tm.put(c,tm.get(c)+1);
            }
        }
        System.out.println(tm);
//        准备StringBuilder
        StringBuilder sb=new StringBuilder();
        tm.forEach(new BiConsumer<Character, Integer>() {
            @Override
            public void accept(Character key, Integer value) {
                sb.append(key).append("(").append(value).append(")");
            }
        });
        System.out.println(sb);
    }
}
